<template>
	<view class="home-wrap u-m-b-20">
		<base-nav-bar :isBack="true" :background="{'background':'#fff'}">
			<text
				slot="content"
				style="color: #333; width: 100%; text-align: center;padding-left: 20rpx;"
			>
				商品订单列表
			</text>
		</base-nav-bar>
		<view class="content-box"  v-if="!isEmpty" style="margin-top: 30rpx;">
			<view class="u-flex u-flex-column u-flex-between merchant-box u-p-t-20 u-m-l-30 u-m-r-30 u-m-b-20" v-for="(item,index) in courseList" :key="index">
				<view class="course-item u-flex u-flex-between u-flex-items-center u-p-l-20 u-p-b-20 u-p-r-20">
					<view class="u-flex u-flex-start u-flex-items-center u-flex-3">
						<image :src="item.image" class="merchant-logo"></image>
						<view class="u-flex u-flex-items-start u-flex-column u-flex-between u-m-l-20" style="min-height: 140rpx;">
							<view class="course-item-text u-ellipsis-2">{{ item.goods_name }}</view>
							<view class="course-item-number">购买人:{{item.nickname?item.nickname:''}}</view>
							<view class="course-item-number">购买时间:{{item.createtime}}</view>
						</view>
					</view>
					<view class="course-item-btn-group u-flex u-flex-1 u-flex-column u-flex-around  u-p-r-20  u-p-t-20 u-p-b-20" v-if="item.status=='1'">
						<view class="course-item-btn edit" @click="jump('/pages-merchant/order/cancelAfterGoods?id='+item.id)">确认核销</view>
						<view class="course-item-btn delete" @click="scanCodeHandler()">扫码核销</view>
					</view>
					<view class="course-item-btn-group u-flex u-flex-1 u-flex-column u-flex-center  u-p-r-20  u-p-t-20 u-p-b-20" v-if="item.status!='1'">
						<view class="course-item-btn final" v-if="item.status=='3'">审核退款</view>
						<view class="course-item-btn final tui" v-if="item.status=='4'">已退款</view>
						<view class="course-item-btn final wancheng" v-if="item.status=='5'">已完成</view>
					</view>
				</view>
			</view>
		</view>
		<!-- 数据为空 -->
		<u-empty
			v-if="isEmpty"
			mode="data"
			:marginTop="220"
			text="暂无商品订单记录"
		>
		</u-empty>
		<!-- 更多 -->
		<u-loadmore v-if="!isEmpty" height="80rpx" :status="loadStatus" icon-type="flower" color="#ccc"/>
	</view>
</template>

<script>
let systemInfo = uni.getSystemInfoSync();
let menuButtonInfo = {};
// #ifdef MP-WEIXIN || MP-BAIDU || MP-TOUTIAO || MP-QQ
menuButtonInfo = uni.getMenuButtonBoundingClientRect();
// #endif
import { mapGetters } from 'vuex';
import { HTTP_IMG_URL,HTTP_UPLOAD_IMG_URL } from '../../config/app.js'
import BaseNavBar from "../../components/BaseNavBar.vue";
export default {
	components: {
		BaseNavBar
	},
	data() {
		return {
			courseList:[
			],
			loadStatus   : 'nomore', //loadmore-加载前的状态，loading-加载中的状态，nomore-没有更多的状态
			currentPage  : 1,
			lastPage     : 1,
			total  : '',
			isEmpty      : false,
			showTui:false,
			tuiMoney:'',
			orderId:''
		};
	},
	computed: {
		...mapGetters(['isLogin', 'userInfo']),
		customBar() {
			let statusBarHeight = systemInfo.statusBarHeight;
			console.log("====statusBarHeight",statusBarHeight)
			// #ifndef MP
			return systemInfo.platform == 'android' ? statusBarHeight + 50 : statusBarHeight + 45;
			// #endif
			// #ifdef MP-WEIXIN
			return menuButtonInfo.bottom + menuButtonInfo.top - statusBarHeight;
			// #endif
			// #ifdef MP-ALIPAY
			return statusBarHeight + systemInfo.titleBarHeight;
			// #endif
		}
	},
	onPullDownRefresh() {
	
	},
	
	onShow() {
		this.courseList = [];
		this.currentPage = 1;
		this.getMourserList()
		
	},
	onHide() {
	},
	onLoad() {
	},
	created() {
		// 触底监听
		uni.$on('uOnReachBottom', data => {
			if (this.loadStatus == 'loadmore') {
				this.currentPage += 1;
				this.getMourserList();
			}
		});
	},
	methods: {
		HTTP_IMG_URL() {
			return HTTP_IMG_URL
		},
		HTTP_UPLOAD_IMG_URL(){
			return HTTP_UPLOAD_IMG_URL
		},
		// 路由跳转
		jump(path, parmas) {
			uni.navigateTo({
				url: path,
				query: parmas
			});
		},
		// 消费列表
		getMourserList() {
			let that = this;
			that.$Api.merchant.goodsOrderList({
				page    : that.currentPage,
				pageSize: 20
			}).then(res => {
				that.courseList = [...that.courseList, ...res.data.data];
				that.isEmpty     = !that.courseList.length;
				that.loadStatus  = that.currentPage < res.data.last_page ? 'loadmore' : 'nomore';
			});
		},
		openTui(id){
			this.showTui = true;
			this.orderId = id;
		},
		scanCodeHandler	(){
			let that = this;
			// 调起条码扫描
			uni.scanCode({
				onlyFromCamera: true, // 是否只能从相机扫码，不允许从相册选择图片
				scanType: ['qrCode'], // 扫码类型 qrCode二维码
				autoZoom: false, 	  // 是否启用自动放大，默认启用
				success: function (res) {
					console.log(`扫码结果：${JSON.stringify(res,null,2)}`);
					that.parseQRCode(res);
				},
				fail: function (err) {
					console.log(`错误：${err}`);
				},
				complete: function (data) {
					console.log('擦屁股！');
				}
			});
		},
		// 解析二维码，处理业务
		parseQRCode(data){
			uni.vibrateShort();					// 震动提示
			// uni.showToast({title: data.result})	// 弹出提示
			this.jump(data.result)
		}
	}
};
</script>

<style lang="scss" scoped>
/* 注意要写在第一行，同时给style标签加入lang="scss"属性 */
.home-wrap {
	min-height: 100vh;
	background: #F6F6F8;
}
.kehu-item {
	border-radius: 20rpx;
	width: 100%;
	.swipers{
		width: 100%;
	}
}
.nickname{
	font-size: 34rpx;
	font-weight: bold;
}
.content-box{
	.merchant-box{
		background:linear-gradient( 180deg, #FFFFFF 0%,#FFFFFF 30%, #FFFFFF 100%);
		box-shadow: 0px 0px 6px 0px rgba(0,0,0,0.1), inset 0px 1px 0px 0px #FFFFFF;
		border-radius: 30rpx;
		min-height: 10vh;
		position: relative;
		.course-item{
			width: 100%;
			margin: 0rpx 0rpx 0rpx;
			.merchant-logo{
				width: 140rpx;
				height: 140rpx;
				border-radius:20rpx;
			}
			.merchant-icon{
				width: 30rpx;
				height: 30rpx;
			}
			.course-item-text{
				font-weight: 400;
				font-size: 32rpx;
				color: #000000;
				width: 46vw;
			}
			.course-item-number{
				font-weight: 400;
				font-size: 13px;
				color: #9A9A9A;
				line-height: 22px;
				text-align: left;
				font-style: normal;
			}
			.course-item-btn-group{
				.course-item-btn{
					width: 78px;
					height: 28px;
					border-radius: 100px;
					display: flex;
					align-items: center;
					justify-content: center;
					font-weight: 500;
				}
				.edit{
					font-size: 28rpx;
					color: #30AA4D;
					background: #EDF7EF;
					border-radius: 22px;
					border: 1px solid #30AA4D;
				}
				.delete{
					margin-top: 20rpx;
					font-size: 28rpx;
					color: #FFB900;
					background: #FFF8E5;
					border-radius: 22px;
					border: 1px solid #FFB900;
				}
				
				.final{
					font-size: 28rpx;
					color: #FFB900;
					background: #FFF8E5;
					border-radius: 22px;
					border: 1px solid #FFB900;
				}
				.tui{
					color: #f18462;
					background: #fff;
					border-radius: 22px;
					border: 1px solid #f3743d;
				}
				.wancheng{
					color: #999;
					background: #fff;
					border-radius: 22px;
					border: 1px solid #9b9a99;
				}
			}
		}
	}
}
.notice-box{
	width: 80vw;
	height: 420rpx;
	border-radius: 20rpx;
	position: relative;
	background: #FFFFFF;
	padding: 20rpx;
	.notice-title{
		margin-top: 32rpx;
		font-weight: 500;
		font-size: 22px;
		color: #FFFFFF;
		line-height: 30px;
		text-align: center;
		font-style: normal;
	}
	.notice-detail{
		font-weight: 400;
		font-size: 12px;
		color: #DAD6D3;
		line-height: 18px;
		text-align: center;
		font-style: normal;
		margin-top: 60rpx;
	}
	.notice-content{
		margin: 14rpx 0;
	}
	.notice-btn{
		width: 100%;
		height: 70rpx;
		border-radius: 100px;
		background: #30AA4D;
		font-weight: 500;
		font-size: 28rpx;
		color: #FFFFFF;
		display: flex;
		align-items: center;
		justify-content: center;
	}
	.back-btn{
		width: 80rpx;
		height: 80rpx;
		border-radius: 100px;
		position: absolute;
		bottom: -30%;
		left: 50%;
		margin-left: -40rpx;
	}
}
::v-deep .u-safe-area-inset-bottom{
	padding-bottom: 30rpx!important;
}
</style>
